﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Zhuang.Model.EF;
namespace Zhuang.WebSite.Areas.SystemManagement.Models.Attributes
{
    public class UserAuthorizeAttribute : AuthorizeAttribute
    {


        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            bool result = true;

            

            if (AppCode.Common.SessionHelper.GetUser() == null)
            {
                result = false;
            }

            string menuId= httpContext.Request.QueryString["menuId"]??"";

            //List<Sys_Menu> userMenus = (List<Sys_Menu>)httpContext.Session["userMenus"];

            //userMenus.Where(um=>um.MenuId=menuId);

            return result;
        }

        //public override void OnAuthorization(AuthorizationContext filterContext) 
        //{ 

        //}


        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException("filterContext");
            }
            else
            {
                string path = filterContext.HttpContext.Request.Path;
                string strUrl = "~/SystemManagement/Login/Index?returnUrl={0}";
                //string strUrl = "www.baidu.com";
                filterContext.HttpContext.Response.Redirect(string.Format(strUrl, HttpUtility.UrlEncode(path)), true);
               

            }

        }
    }
}